/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.vienthonga.register.logic;


import com.vienthonga.hibernate.dao.UserDAO;
import com.vienthonga.hibernate.pojo.TUser;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author DoanHa
 */
public class RegisterLogic {

    public boolean Register(TUser user)
    {              
        // su dung project DAO
        String roleName = "User";
        UserDAO userDAO = new UserDAO();  
        boolean result = userDAO.RegisterAccount(user.getUFullname(),
                user.getUEmail(), user.getUPassword(), roleName);
        return result;

    }

    public boolean CheckExistEmail(String email)
    {
        UserDAO userDAO = new UserDAO();
        boolean result = userDAO.CheckExistEmail(email);

        return result;
    }

    public boolean CheckCaptcha(HttpServletRequest request, String captcha)
    {
        String answer = (String) request.getSession().getAttribute("CorrectAnswer");
        if(answer==null || captcha == null || !answer.equals(captcha))
        {
            return false;
        }

        return true;
    }
}
